<template>
  <div class="teleportDomWrap">
    <h2>自定义指令</h2>
    <h4 class="tempDemo">示例一：动态变量名/值 + 修饰符获取</h4>
    <input type="range" min="0" max="500" v-model="pinPadding" />
    <p v-pin:[direction].foo="pinPadding">Stick me {{ pinPadding + "px" }} from the {{ direction || "top" }} of the page</p>
  </div>
</template>

<script lang="ts">
import { defineComponent } from "vue";
export default defineComponent({
  components: {},
  data() {
    return {
      direction: "right",
      pinPadding: 200,
    };
  },
  directives: {
    pin: {
      mounted(el, binding) {
        // 修饰符
        console.log("修饰符对象---", binding.modifiers);
        console.log("变量名---", binding.arg);
        console.log("变量值---", binding.value);
        el.style.position = "fixed";
        const s = binding.arg || "top";
        el.style[s] = binding.value + "px";
      },
      updated(el, binding) {
        console.log("变量值 旧值---", binding.oldValue);
        console.log("变量值 新值---", binding.value);
        const s = binding.arg || "top";
        el.style[s] = binding.value + "px";
      },
    },
  },
  methods: {},
});
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
